package queries;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import entitys.AddressSale;
import entitys.Request;
import enums.Result;

public class AddAddressSaleQuery {
/**
 * Execute query
 * @param req
 * @param conn
 * @return
 */
	public static Result exe(Request req, Connection conn) {
		Statement stmt;
		AddressSale sale= (AddressSale) req.getEntity();
		try {
			stmt = conn.createStatement();
			stmt.executeUpdate("INSERT INTO `ccrm`.`sales` (`sold`, `productID`, `custID`, `empID`, `review`,`marketingsaleid`) VALUES ('"+sale.getSold()+"', '"+sale.getProductID()+"', '"+sale.getCustomerID()+"', '"+sale.getEmployeeID()+"', '"+((sale.getSold()==1?null:sale.getReview()))+"','"+sale.getMarketingSaleID()+"');");
			stmt.executeUpdate("UPDATE `ccrm`.`marketingsalesaddressing` SET `addressed`='1' WHERE `marketingSaleID`='"+sale.getMarketingSaleID()+"' and`customerID`='"+sale.getCustomerID()+"' and`empID`='"+req.getUserID()+"';");
			return Result.OK;
		
			
			
	 		
		} catch (SQLException e) {	return Result.ERROR;}
		
		
	}



}
